package com.bdzl.biz.controller;

import java.util.List;
import java.util.Map;

import com.bdzl.pub.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bdzl.pub.entity.loan.OrderRelDO;
import com.bdzl.biz.service.OrderRelService;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;

/**
 * 贷款主订单关系人表，主要用于记录贷款人的一些联系人信息，包括担保人、联系人等。
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-11 15:23:42
 */

@Controller
@RequestMapping("/bdzl/orderRel")
public class OrderRelController extends BaseController {
	@Autowired
	private OrderRelService orderRelService;

	@GetMapping()
	String OrderRel(){
	    return "bdzl/orderRel/orderRel";
	}

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<OrderRelDO> orderRelList = orderRelService.list(query);
		int total = orderRelService.count(query);
		PageUtils pageUtils = new PageUtils(orderRelList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "bdzl/orderRel/add";
	}

	@GetMapping("/edit/{relId}")
	String edit(@PathVariable("relId") Integer relId,Model model){
		OrderRelDO orderRel = orderRelService.get(relId);
		model.addAttribute("orderRel", orderRel);
	    return "bdzl/orderRel/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( OrderRelDO orderRel){
		if(orderRelService.save(orderRel)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( OrderRelDO orderRel){
		orderRelService.update(orderRel);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer relId){
		if(orderRelService.remove(relId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] relIds){
		orderRelService.batchRemove(relIds);
		return R.ok();
	}

}
